package ngat.oss;

import ngat.phase2.*;
import java.io.*;
import java.util.*;

public class TestUpdateGroupTimes {


    public static void main (String[] args) {

	String pname  = args[0];

	Proposal proposal = null;

	try {
	    File file = new File(pname);
	    ObjectInputStream fin = new ObjectInputStream(new FileInputStream(file));	
	    	    
	    try {
		proposal = (Proposal)fin.readObject();
		System.err.println("Fix::Read prop back from: "+file.getPath());
		fin.close();		   
		fin = null;
		file= null;
	    } catch (ClassNotFoundException cx) {
		proposal = null;
	    }
	    
	} catch (Exception e) {
	    System.err.println("FixExecTimes:Error reading proposal: "+pname+" : "+e);
	    return;
	}
	
	if (proposal == null) {
	    System.err.println("Proposal was null");
	    return;
	}
	
	
	Iterator ig = proposal.listAllGroups();
	while (ig.hasNext()) {
	    Group group = (Group)ig.next();
	    Scheduling.calculateExecutionTimes(group);
	}

	try {
	    File file = new File(pname);
	    ObjectOutputStream fout = new ObjectOutputStream(new FileOutputStream(file));
	    fout.flush();
	    fout.writeObject(proposal);
	    fout.flush();
	    fout.close();
	} catch (Exception e) {
	    System.err.println("FixExecTimes:Error storing proposal: "+pname+" : "+e);
	}
    }    

} 
